<html>
<head><meta charset="utf-8"><title>What does std::simd need from floats? · project-portable-simd · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/index.html">project-portable-simd</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html">What does std::simd need from floats?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214766461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214766461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214766461">(Oct 27 2020 at 21:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281757">Jubilee</span> <a href="#narrow/stream/257879-project-portable-simd/topic/meeting.202020-10-26/near/214629070">said</a>:</p>
<blockquote>
<p>I. am working on analyzing our float situation and am interested in hearing others on desirables.</p>
</blockquote>
<p>From the const eval and unsafe code perspective, what is desired is super-reliable, predictable behavior, where runtime performance doesn't matter as long as we have strong guarantees, so then we can do tricks that let us have <em>less</em> of a runtime.</p>
<p>From the SIMD perspective, I'm guessing what we would _like_ is to be able to tightly control performance characteristics? But I'm wondering if that's just an assumption I'm making and if others feel the same about it.</p>



<a name="214767529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214767529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214767529">(Oct 27 2020 at 21:37)</a>:</h4>
<p>I think we're close to potentially being able to expose safe (definitely non-deterministic) "fast" math through LLVM freeze, if that would be helpful for what you're up to.  <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Taking.20advantage.20of.20.60freeze.60.3F/near/212979135">https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Taking.20advantage.20of.20.60freeze.60.3F/near/212979135</a></p>



<a name="214767818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214767818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214767818">(Oct 27 2020 at 21:40)</a>:</h4>
<p>i think you want more than just a toggle for fast/not fast tbh... in general IMO the reordering, precision relaxation, and etc parts of ffast-math are more valuable (and less footgun-ey) than the "pretend infinity and nan dont exist" (the infinity one is <em>especially</em> footguney)</p>



<a name="214768531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214768531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214768531">(Oct 27 2020 at 21:46)</a>:</h4>
<p>Yeah, I have been eyeing that difference too. Rust really would rather control various things that are already considered acceptable variation under IEEE754 than the optimizations that <em>deviate</em> from floating point.<br>
only half-joking: if we had dependent types we could make this all easy! :^)</p>



<a name="214770503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214770503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214770503">(Oct 27 2020 at 22:06)</a>:</h4>
<p><code>RelaxedFloat&lt;f64, AllowReciprocal&gt;</code>? Could lower that to the corresponding llvm fast-math flags...</p>



<a name="214770976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214770976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214770976">(Oct 27 2020 at 22:10)</a>:</h4>
<p>iirc, SIMD stuff on intel at least uses the FP state, but LLVM doesn't let you change the FP state. So until LLVM lets you change FP state, what we really get is "default FP state" floats only.</p>



<a name="214773820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214773820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214773820">(Oct 27 2020 at 22:41)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> that's not part of the FP state, it's the set of optimizations that LLVM is allowed to do.</p>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> I don't know about the LLVM internals, it's almost possible to implement AllowReciprocal entirely in software if it's its own type by e.g. <code>impl Div</code> as <code>* (1.0 / self)</code>... I think also for simd we'd prefer it not to be purely type-based to avoid more combinatoric type explosion...</p>
<p>Perhaps it wouldn't matter though.</p>



<a name="214774868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214774868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214774868">(Oct 27 2020 at 22:54)</a>:</h4>
<p>Agreed on making it type wrappers as much as possible</p>



<a name="214775029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214775029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214775029">(Oct 27 2020 at 22:56)</a>:</h4>
<p>Worst case it could use an unstable trait to implement the wrapper</p>



<a name="214775098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214775098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214775098">(Oct 27 2020 at 22:57)</a>:</h4>
<p>So there's a nuance here where what functions we link against and what code we emit to LLVM in the first place can significantly change the results and speed of floating point operations, even after LLVM optimizations, even without changing the surface semantics, and remaining within acceptable variation as perceived by IEEE754.</p>



<a name="214775457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214775457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214775457">(Oct 27 2020 at 23:01)</a>:</h4>
<p>Do you have an example?  Not sure I'm following</p>



<a name="214782741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214782741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214782741">(Oct 28 2020 at 00:35)</a>:</h4>
<p>one example might be which way LLVM translates a fadd to the target ISA, if it uses <code>a + b</code> that gives different results to <code>b + a</code> since, if <code>a</code> and <code>b</code> are different quiet NaNs, one way it will return <code>a</code> and the other way will return <code>b</code>. This is true for almost all ISAs: RISC-V doesn't have that issue since it returns the canonical NaN instead of <code>a</code> or <code>b</code>; x87 doesn't have that issue since it has special hardware to compare <code>a</code> and <code>b</code>'s payloads and pick the max/min (ICR which), though x87 has its own mountain of oddities.</p>



<a name="214783274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214783274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214783274">(Oct 28 2020 at 00:42)</a>:</h4>
<p>Another example is...</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="c1">// Rust</span>
<span class="w">    </span><span class="n">bridge</span><span class="p">.</span><span class="n">d</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">bridge</span><span class="p">.</span><span class="n">a</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">f64</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">bridge</span><span class="p">.</span><span class="n">b</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">f64</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">bridge</span><span class="p">.</span><span class="n">c</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">f64</span><span class="p">)</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">f32</span><span class="p">;</span><span class="w"></span>
</code></pre></div>

<div class="codehilite" data-code-language="C++"><pre><span></span><code><span class="c1">// C++</span>
    <span class="n">bridge</span><span class="p">.</span><span class="n">d</span> <span class="o">=</span> <span class="n">bridge</span><span class="p">.</span><span class="n">a</span> <span class="o">*</span> <span class="n">bridge</span><span class="p">.</span><span class="n">b</span> <span class="o">+</span> <span class="n">bridge</span><span class="p">.</span><span class="n">c</span><span class="p">;</span>
</code></pre></div>

<p>emit the same IR.<br>
( or did at one point, I'd have to double check since this example is old. )</p>



<a name="214783567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214783567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214783567">(Oct 28 2020 at 00:46)</a>:</h4>
<p><span class="user-mention" data-user-id="281757">@Jubilee</span> you mean as opposed to using f32 multiplication?</p>



<a name="214784005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214784005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214784005">(Oct 28 2020 at 00:51)</a>:</h4>
<p>yeah C++ lets you do some pretty cursed implicit coercions. :^)</p>



<a name="214785976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214785976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214785976">(Oct 28 2020 at 01:20)</a>:</h4>
<p><span class="user-mention" data-user-id="281757">@Jubilee</span> That seems like optimizing it needs the "assume no infinities" flag that Thom mentioned as being particularly errorprone</p>
<p>(because a and b are positive and c is negative, the calculation could be infinite in f32 but finite in f64)</p>



<a name="214786335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214786335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214786335">(Oct 28 2020 at 01:27)</a>:</h4>
<p>Indeed. And yeah, I'm reading Kahan go on a rant about Java's (early) choices in terms of FP (he is... acidic) and a thing he lingers on for a while is how infinities are actually more of a problem than NaNs with single-precision and computer architectures often run doubles at equivalent speed, so you should evaluate intermediates as doubles but store in whatever.</p>



<a name="214786538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214786538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214786538">(Oct 28 2020 at 01:30)</a>:</h4>
<p>I'm not particularly advocating for implicit promotion to doubles, I'm just pointing out that some surprising stuff can happen with floating point evaluation.</p>



<a name="214786836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214786836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214786836">(Oct 28 2020 at 01:35)</a>:</h4>
<p><a href="https://www2.math.uconn.edu/~olshevsky/classes/2017_Fall/math5510/JAVAhurt.pdf">https://www2.math.uconn.edu/~olshevsky/classes/2017_Fall/math5510/JAVAhurt.pdf</a>?</p>



<a name="214789100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214789100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214789100">(Oct 28 2020 at 02:11)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281757">Jubilee</span> <a href="#narrow/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F/near/214786538">said</a>:</p>
<blockquote>
<p>I'm not particularly advocating for implicit promotion to doubles, I'm just pointing out that some surprising stuff can happen with floating point evaluation.</p>
</blockquote>
<p>I'd argue for avoiding <code>f64</code> unless you actually need it -- with automatic vectorization <code>f32</code> is often twice as fast since the compiler can cram twice as many values in a SIMD register.</p>



<a name="214789432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214789432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214789432">(Oct 28 2020 at 02:16)</a>:</h4>
<p>I'd have to double check, but I think <code>(a as f64 * b as f64 + c as f64) as f32</code> is exactly the same as <code>f32::mul_add(a, b, c)</code> if you treat all NaNs the same. It does properly account for when <code>f32::mul(a, b)</code> is an infinity due to overflow.</p>



<a name="214790365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/214790365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#214790365">(Oct 28 2020 at 02:35)</a>:</h4>
<p>turns out I was wrong: I forgot to account for double rounding. it would work with intermediate values with more than about 72 bits of mantissa, so <code>f128</code> would work, but not <code>f64</code>. An interesting paper related to that <a href="https://hal.archives-ouvertes.fr/hal-01091186">https://hal.archives-ouvertes.fr/hal-01091186</a></p>



<a name="215268519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/What%20does%20std%3A%3Asimd%20need%20from%20floats%3F/near/215268519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jed <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/What.20does.20std.3A.3Asimd.20need.20from.20floats.3F.html#215268519">(Nov 01 2020 at 23:40)</a>:</h4>
<p>I can comment briefly as a maintainer of PETSc (a widely-used distributed-memory algebraic solvers library) and broader computational science practitioner. I think <code>fp-contract=fast</code> should be default (or easy to select at crate granularity). Many applications are also fine with associative math project-wide, so long as they can guarantee it in the select places where it counts. Note that supporting associative math is essential for reductions (like norms and inner products) to run at load-store throughput, and it's implied by the likes of <code>#pragma omp simd reduction(+:sum)</code>. If crates need to use special types to get FMA contractions and associative math, a lot of potential adopters of Rust will conclude that the language is slow or too onerous for numerical code and thus stick with C/C++/Fortran.</p>
<p>The rest of <code>-ffast-math</code> is more delicate. There are certainly apps that are happy to enable all of it. I'd estimate such apps account for 20-50% of supercomputer time today. ICC has almost <code>-ffast-math</code> semantics by default and a sizable cohort of apps like it (and sometimes mistakenly conclude it's faster than gcc/clang because they are more conservative without <code>-ffast-math</code>).</p>
<p>I realize I'm breaking with Kahan (1998) on associativity defaults (or coarse-grained opt-in), though this is informed by what kind of code is written by which sort of developers. Really delicate numerics in the likes of eigensolvers are usually written by competent numerical analysts. Substantial amounts of library and application code supports semantics similar to matrix multiplication (taking advantage of sparsity and other structure). But the bulk of lines and code-churn in applications is implementing physical models such as conservation laws and constitutive models, and much of this is written by domain scientists with little software engineering experience and no input by numerical analysts. They want it to run fast, and every once in a while may encounter numerical issues such as computing a negative pressure from a near-vacuum state (that should produce a tiny positive pressure). This is often when a numerical analyst is brought in to help debug, and would be a place to use types that enforce stricter semantics.</p>
<p>I never run trapping floating point in production, but it's an extremely useful debugging tool, both whole-project and selectively. It's most convenient to enable project-wide and have functions that intentionally handle denormals push non-trapping mode on entry and pop on return. We do this in PETSc around eigensolvers, for example, while providing a convenient run-time option to enable trapping at initialization.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>